package com.logistics.utils.message;

import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.util.ResourceBundle;

public class Manager {

    private static ResourceBundle resourceBundle = ResourceBundle.getBundle("message/message", new Locale( "zh",  "CN"));

    public static String getMessage(String msgId){
        String message = null;
        try {
            message =  new String(resourceBundle.getString(msgId).getBytes("ISO-8859-1"),
                    "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return message;
    }

    public static String getMessage(String msgId, String... str){
        String message = null;
        try {
            message =  new String(resourceBundle.getString(msgId).getBytes("ISO-8859-1"),
                    "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if(null != message){
            if(null != str && !"".equals(str)){
                for(int i=0; i< str.length; i++){
                    message = message.replace("{"+i+"}", str[i]);
                }
            }
        }
        return message;
    }
}
